package com.chenhy.springbootvuesmbms.service;

import com.chenhy.springbootvuesmbms.mapper.BillMapper;
import com.chenhy.springbootvuesmbms.pojo.Bill;
import com.chenhy.springbootvuesmbms.pojo.Provider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BillServiceImpl implements BillService {

    @Autowired
    private BillMapper billMapper;

    @Autowired
    private ProviderService providerService;

    @Override
    public List<Bill> queryAllBill() {
        return billMapper.queryAllBill();
    }

    @Override
    public List<Bill> fuzzyBillQuery(String condition) {
        return billMapper.fuzzyBillQuery(condition);
    }

    @Override
    public int addBill(Bill bill) {
//        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        bill.setCreatedBy(loginUser.getId());
//        bill.setModifyBy(loginUser.getId());
//        return billMapper.addBill(bill);
        return 0;
    }

    @Override
    @Transactional
    public Bill queryBillById(int id) {
        Bill bill = billMapper.queryBillById(id);
        Provider provider = providerService.queryProviderById(bill.getProviderId());
        bill.setProviderName(provider.getProName());
        return bill;
    }
//
    @Override
    public int updateBill(Bill bill) {
//        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        bill.setModifyBy(loginUser.getId());
//        return billMapper.updateBill(bill);
        return 0;
    }

    @Override
    public int deleteBill(int id) {
        return billMapper.deleteBill(id);
    }
}
